package com.llu.demo.entity;


import com.llu.demo.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author jackliu  Email:
 * @description: 封装返回的数据
 * @Version
 * @create 2024-06-23 22:03
 */
@Data
public class Result<T> {
    private boolean success ;
    private Integer code ;
    private String message ;
    private T data ;

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return result;
    }
    public static Result error(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAILED.getCode());
        result.setMessage(ResultCodeEnum.FAILED.getMessage());
        return result;
    }
        //  带数据的SUCCESS
    public static <T> Result<T> ok(T data){
        Result result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }
    // 带数据的 FAILED
    public static <T> Result error(T data){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAILED.getCode());
        result.setMessage(ResultCodeEnum.FAILED.getMessage());
        result.setData(data);
        return result;
    }

}
